<?php
/**
 * Created by PhpStorm.
 * User: cyc
 * Date: 2017/11/1
 * Time: 下午2:53
 */

class ApiVideoService extends ApiBaseService
{

//**params**:
//
//param | required | type   |describe
//----  |------    |------  |----
//id  | false    |int       |视频ID默认为空返回所有视频，
//size  | false    |int     |分页大小,默认为0
//offset| false    |int     |偏移量，默认为1个
//{
//"id":1,//唯一id
//"name":"每日大法好",//名称
//"avater":"http://tv.libooc.com/avater/topic/xxx.jpg",
//"source":
//{
//"cq"//高清:"",
//"gq"//超清:"",
//"bq"//标清:"",
//
//}
//
//},

    public static function detailAction($params)
    {

        $id = self::util_array_get($params, 'id',null);
        $page = self::util_array_get($params, 'page', 0);
        $size = self::util_array_get($params, 'size', 1);
        $videos = [];
        $criteria = new CDbCriteria();
        if($id)
        {
            $criteria->addColumnCondition(['id' => $id]);
        }
        $criteria->offset = $page;
        $criteria->limit = $size;


        foreach (Video::model()->findAll($criteria) as $video) {
            $videos[] = ['id' => $video->id, 'name' => $video->name, 'avater' => $video->avetar,
                'source'=>$video->getSources()];
        }
        if($id)
        {
            $videos = isset($videos[0])?$videos[0]:null;
        }
        return $videos;
    }

}